package com.example.daytest.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @author heyu
 * @title: YangController
 * @description:计算
 * @date 2022/12/19上午11:03
 */
@RestController
public class YangController {
    @Autowired
    ResourceLoader resourceLoader;

    @RequestMapping(value = "/get",method = RequestMethod.GET)
    public JSONArray jiedaoData() throws Exception{
        Resource resource = resourceLoader.getResource("classpath:pcas-code.json");
        InputStream is = resource.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String data = null;
        StringBuilder str=new StringBuilder();
        while((data = br.readLine()) != null) {
            str.append(data);

        }

        br.close();
        isr.close();
        is.close();


        return  JSONObject.parseArray(str.toString());

    }
}
